package jjn.round1;

/**
 * @author Jiang Jining
 * @since 2023-05-28 20:08
 */
public class LeetCode75_SortColors {
    public void sortColors(int[] nums) {
        int start = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                swap(nums, i, start);
                start++;
            }
        }
        for (int i = start; i < nums.length; i++) {
            if (nums[i] == 1) {
                swap(nums, i, start);
                start++;
            }
        }
    }
    
    private void swap(int[] nums, int i, int j) {
        int temp = nums[j];
        nums[j] = nums[i];
        nums[i] = temp;
    }
}
